package com.woniu.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.woniu.domain.Position;
import com.woniu.dto.Result;
import com.woniu.dto.StatusCode;
import com.woniu.service.PositionAndCompanyService;
import com.woniu.service.PositionDetailsService;
import com.woniu.service.PositionService;
import com.woniu.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.woniu.domain.Position;
import com.woniu.dto.Result;
import com.woniu.dto.StatusCode;
import com.woniu.service.PositionService;
import com.woniu.vo.DataPie;
import org.springframework.web.bind.annotation.GetMapping;
import com.woniu.dto.Result;
import com.woniu.dto.StatusCode;
import com.woniu.service.PositionService;
import com.woniu.vo.PositionDetailsVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PathVariable;

import javax.annotation.Resource;
import java.util.List;

import javax.annotation.Resource;
import java.util.List;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyy
 * @since 2021-03-05
 */
@RestController
@RequestMapping("/position")
@Api(tags = "职位服务接口信息")//用于描述接口类的相关信息，作用于类上
public class PositionController {
    @Resource
    PositionService positionService;

    @Resource
    private PositionAndCompanyService positionAndCompanyService;

    //    职位详情页面数据

    @GetMapping("jobTitle")
    @ApiOperation(value = "职位详情页面数据",notes = "<span style='color:red;'>职位详情页面数据</span>")
    @ApiImplicitParams({
            //dataType:参数类型
            //paramType:参数由哪里获取     path->从路径中获取，query->?传参，body->ajax请求
            @ApiImplicitParam(name = "positionId",value = "职位id",dataType = "Integer",paramType = "path",example = "java各工程师"),

    })
    public Result jobTitle(Integer positionId){
        PositionDetailsVo positionDetailsVo = positionService.jobTitle(positionId);
        if (ObjectUtils.isEmpty(positionDetailsVo)) {
            return new Result(false, StatusCode.ERROR,"失败");
        }
        return new Result(true, StatusCode.OK,"成功",positionDetailsVo);
    }


    //    modifyStatus 点击投递简历按钮
    @GetMapping("modifyStatus")
    @ApiOperation(value = "点击投递简历按钮",notes = "<span style='color:red;'>点击投递简历按钮</span>")
    @ApiImplicitParams({
            //dataType:参数类型
            //paramType:参数由哪里获取     path->从路径中获取，query->?传参，body->ajax请求
            @ApiImplicitParam(name = "positionId",value = "职位id",dataType = "Integer",paramType = "path",example = "java各工程师"),
            @ApiImplicitParam(name = "uid",value = "用户id",dataType = "Integer",paramType = "path",example = "java各工程师"),
    })
    public  Result modifyStatus(Integer positionId,Integer  uid){
//        Integer userId =3;
        Integer integer = positionService.modifyStatus(positionId, uid);
        if (integer>0){
            return new Result(true, StatusCode.ERROR,"true");
        }
        return new Result(false, StatusCode.ERROR,"false");
    }

    //根据公司id查询该公司下的所有职位
    @GetMapping("queryPositionByCid/{compId}")
    public Result queryPositionByCid(@PathVariable Integer compId){
        System.out.println(compId);
        List<DataPie> positions = positionService.queryPositionByCid(compId);
        System.out.println(positions);
        return new Result(true, StatusCode.OK,"查询成功",positions);
    }

    /**
     * @Author Lints
     * @Date 2021/3/8/008 13:27
     * @Description
     * @Param [LikePositionVo]
     * @Return com.woniu.dto.Result
     * @Since version-1.0
     */
    @GetMapping("getLikePosition")
    public Result getJobUser(LikePositionVo conditionVo){
        System.out.println("getLikePosition==============\n");
        IPage<PositionAndCompany> positionAndCompany = positionAndCompanyService.getPositionAndCompany(conditionVo);
        return new Result(true, StatusCode.OK,"查询公司职位成功",positionAndCompany);
    }

    @GetMapping("getHotPositions")
    public Result getHotPositions(){
        List<Position> positionAndCompany = positionService.getHotPositions();
        return new Result(true, StatusCode.OK,"查询热门公司职位成功",positionAndCompany);
    }

/*
*
* */

    //分页无条件查询

    @GetMapping("/findPage")
    @ApiOperation(value = "招聘者查看职位",notes = "<span style='color:red;'>查看自己公司所有职位</span>")
    public Result findPage(PositionVo positionVo,Integer uid){
        return new Result(true,StatusCode.OK,
                "分页查询",positionService.getPage(positionVo,uid));
    }

    //有条件分页查询
    @GetMapping("/conditionPage")
    @ApiOperation(value = "招聘者查看职位",notes = "<span style='color:red;'>查看搜索的职位</span>")
    public Result conditionPage(PositionVo positionVo,Integer uid){
        return new Result(true, StatusCode.OK,
                "分页查询成功",positionService.conditionPage(positionVo,uid));
    }

    @GetMapping("showPer/{uid}")
    @ApiOperation(value = "点击验证公司状态",notes = "<span style='color:red;'>查询公司状态</span>")
    public Result showPer(@PathVariable Integer uid){
        String status=positionService.selectStatus(uid);
        if (status.equals("已通过")){
            return null;
        }else {
            return new Result(false,StatusCode.ERROR,"公司未通过审核");
        }
    }
    //添加职位
    @PostMapping("/add/{uid}")
    @ApiOperation(value = "添加职位",notes = "<span style='color:red;'>添加职位</span>")
    public Result add(@RequestBody Position position, @PathVariable Integer uid){
        if (position.getStatusc().equals("true")){
            position.setStatusc("发布");
        }else{
            position.setStatusc("下架");
        }
        position.setHot("非热点");
        Position position1 = positionService.addPosition(position, uid);
        return new Result(true, StatusCode.OK,
                "新增成功",position1);
    }

    //删除职位
    @GetMapping("deleteP")
    @ApiOperation(value = "删除职位",notes = "<span style='color:red;'>删除职位</span>")
    public Result deleteP(@RequestParam List<String> Ids){
        positionService.deleteP(Ids);
        return new Result(true,StatusCode.OK,"删除成功");
    }
    //修改之前先查询
    @GetMapping("selectP/{id}")
    @ApiOperation(value = "查看职位详情",notes = "<span style='color:red;'>查询职位</span>")
    public Result selectP(@PathVariable String id){
        return new Result(true,StatusCode.OK,
                "查询",positionService.selectP(id));
    }

    //修改
    @PutMapping("/updateP")
    @ApiOperation(value = "修改职位详情",notes = "<span style='color:red;'>修改职位</span>")
    public Result updateP(@RequestBody Position position){

        positionService.updateP(position);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    //发布页分页查询
    @GetMapping("/statusUp")
    @ApiOperation(value = "发布页分页查询",notes = "<span style='color:red;'>发布页分页查询</span>")
    public Result statusUp(PositionVo positionVo,Integer uid){
        return new Result(true, StatusCode.OK,
                "分页查询成功",positionService.statusPage(positionVo,uid,"发布"));
    }

    //下架页分页查询
    @GetMapping("/statusDown")
    @ApiOperation(value = "下架页分页查询",notes = "<span style='color:red;'>下架页分页查询</span>")
    public Result statusDown(PositionVo positionVo,Integer uid){
        return new Result(true, StatusCode.OK,
                "分页查询成功",positionService.statusPage(positionVo,uid,"下架"));
    }

    @GetMapping("/updateDown")
    @ApiOperation(value = "下架操作",notes = "<span style='color:red;'>下架操作</span>")
    public Result updateDown(@RequestParam List<String> Ids){
        for (String id:Ids){
            Position position = positionService.selectP(id);
            position.setStatusc("下架");
            UpdateWrapper<Position> wrapper = new UpdateWrapper<>();
            wrapper.eq("position_id",position.getPositionId());
            positionService.update(position,wrapper);
        }
        return new Result(true,StatusCode.OK,"下架成功");
    }

    @GetMapping("/updateUp")
    @ApiOperation(value = "发布操作",notes = "<span style='color:red;'>发布操作</span>")
    public Result updateUp(@RequestParam List<String> Ids){
        for (String id:Ids){
            Position position = positionService.selectP(id);
            position.setStatusc("发布");
            UpdateWrapper<Position> wrapper = new UpdateWrapper<>();
            wrapper.eq("position_id",position.getPositionId());
            positionService.update(position,wrapper);
        }

        return new Result(true,StatusCode.OK,"发布成功");
    }


}

